package bb.lanxing.net.core;

import java.util.Objects;

public final class ApiCookie {
    private final String domain;
    private final long expiresAt;
    private final String name;
    private final String path;
    private final String value;

    private ApiCookie(String name, String value, long expiresAt, String domain, String path) {
        this.name = name;
        this.value = value;
        this.expiresAt = expiresAt;
        this.domain = domain;
        this.path = path;
    }

    private ApiCookie(Builder builder) {
        Objects.requireNonNull(builder.name, "builder.name == null");
        Objects.requireNonNull(builder.value, "builder.value == null");
        Objects.requireNonNull(builder.domain, "builder.domain == null");
        this.name = builder.name;
        this.value = builder.value;
        this.expiresAt = builder.expiresAt;
        this.domain = builder.domain;
        this.path = builder.path;
    }

    public String name() {
        return this.name;
    }

    public String value() {
        return this.value;
    }

    public long expiresAt() {
        return this.expiresAt;
    }

    public String domain() {
        return this.domain;
    }

    public String path() {
        return this.path;
    }

    public static final class Builder {
        String domain;
        String name;
        String value;
        long expiresAt = Long.MAX_VALUE;
        String path = "/";

        public Builder domain(String domain) {
            return this;
        }

        public Builder name(String name) {
            this.name = name;
            return this;
        }

        public Builder value(String value) {
            this.value = value;
            return this;
        }

        public Builder expiresAt(long expiresAt) {
            this.expiresAt = expiresAt;
            return this;
        }

        public Builder path(String path) {
            this.path = path;
            return this;
        }

        public ApiCookie build() {
            return new ApiCookie(this);
        }
    }
}
